import { reactive } from 'vue'
import type { FormRules } from 'element-plus'

/** 密码正则（密码格式应为8-18位数字、字母、符号的任意两种组合） */
export const REGEXP_PWD =
  /^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)]|[()])+$)(?!^.*[\u4E00-\u9FA5].*$)([^(0-9a-zA-Z)]|[()]|[a-z]|[A-Z]|[0-9]){8,18}$/
export const REGEXP_PHONE = /^1[3-9]\d{9}$/

const bindRules = reactive(<FormRules>{
  phone: [
    {
      validator: (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入手机号码'))
        }
        // else if (!REGEXP_PHONE.test(value)) {
        //   callback(new Error('请输入正确的手机号码'))
        // }
        else {
          callback()
        }
      }
    }
  ],
  code: [
    {
      validator: (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入短信验证码'))
        } else {
          callback()
        }
      },
      trigger: 'blur'
    }
  ],
  captcha: [
    {
      validator: (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入图形验证码'))
        } else {
          callback()
        }
      },
      trigger: 'blur'
    }
  ]
})

export { bindRules }
